package com.example.myapplication.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;

import com.example.myapplication.PersonDatabase;
import com.example.myapplication.dao.PersonDao;
import com.example.myapplication.model.Person;
import com.example.myapplication.repository.PersonRepository;

import java.util.List;

public class PersonViewModel extends AndroidViewModel {
    private PersonDao personDao;
    private LiveData<List<Person>> allPersonLive;
    private PersonRepository personRepository;
    public LiveData<List<Person>> getAllPersonLive() {
        return personRepository.getAllPersonLive();
    }

    public PersonViewModel(@NonNull Application application) {
        super(application);
        PersonDatabase personDatabase=PersonDatabase.getDatabase(application);
        personRepository=new PersonRepository(application);
    }

    public void insertPerson(Person...people){
        personRepository.insertPerson(people);
    }

    public void clearPerson(){
        personRepository.deleteAllPerson();
    }


}
